﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YArchitech.Plumbing
{
	public partial class FormWareByWall : System.Windows.Forms.Form
	{
		public FormWareByWall()
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
			this.InitUserSetting();
		}

		private void InitUserSetting()
		{
			if (this.userSetting.GetValue("LayWares", "EquipCount") != "")
			{
				this.txtEquipCount.Value = Convert.ToDecimal(this.userSetting.GetValue("LayWares", "EquipCount"));
			}
			if (this.userSetting.GetValue("LayWares", "WallDistance") != "")
			{
				this.txtWallFaceDistance.Text = this.userSetting.GetValue("LayWares", "WallDistance");
			}
			if (this.userSetting.GetValue("LayWares", "EquipOffset") != "")
			{
				this.txtWallPointDistance.Text = this.userSetting.GetValue("LayWares", "EquipOffset");
			}
			if (this.userSetting.GetValue("LayWares", "EquipDistance") != "")
			{
				this.txtEquipDistance.Text = this.userSetting.GetValue("LayWares", "EquipDistance");
			}
		}

		private void txtEquipCount_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.equipCount = (int)Convert.ToInt16(this.txtEquipCount.Value);
			}
			catch
			{
			}
		}

		private void txtEquipDistance_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.equipDistance = (int)Convert.ToInt16(this.txtEquipDistance.Text);
			}
			catch
			{
			}
		}

		private void txtWallFaceDistance_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.wallFaceDistance = (int)Convert.ToInt16(this.txtWallFaceDistance.Text);
			}
			catch
			{
			}
		}

		private void txtWallPointDistance_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.wallPointDistance = (int)Convert.ToInt16(this.txtWallPointDistance.Text);
			}
			catch
			{
			}
		}

		private void txtEquipCount_ValueChanged(object sender, EventArgs e)
		{
			if (this.txtEquipCount.Value < 1m)
			{
				this.txtEquipCount.Value = 1m;
			}
		}

		private void button2_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnConfirm_Click(object sender, EventArgs e)
		{
			try
			{
				this.SetUserData();
				this.equipCount = Convert.ToInt32(this.txtEquipCount.Value);
				this.equipDistance = Convert.ToInt32(this.txtEquipDistance.Text);
				this.wallFaceDistance = Convert.ToInt32(this.txtWallFaceDistance.Text);
				this.wallPointDistance = Convert.ToInt32(this.txtWallPointDistance.Text);
			}
			catch (Exception)
			{
			}
			base.DialogResult = DialogResult.OK;
		}

		private void SetUserData()
		{
			this.userSetting.WriteValue("LayWares", "EquipCount", this.txtEquipCount.Value.ToString());
			this.userSetting.WriteValue("LayWares", "WallDistance", this.txtWallFaceDistance.Text);
			this.userSetting.WriteValue("LayWares", "EquipOffset", this.txtWallPointDistance.Text);
			this.userSetting.WriteValue("LayWares", "EquipDistance", this.txtEquipDistance.Text);
		}

		private UserSetting userSetting = new UserSetting();

		public int equipCount = 3;

		public int equipDistance = 1200;

		public int wallFaceDistance;

		public int wallPointDistance;
	}
}
